#!/usr/bin/python3
# coding=utf-8
#
# Copyright (C) 2023-2025. Huawei Technologies Co., Ltd. All rights reserved.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# ===============================================================================

import numpy as np
import torch
# import tensorflow as tf
# bfloat16 = tf.bfloat16.as_numpy_dtype
dtype_emu = {
    # bfloat16: 0,
    np.float16: 1,
    np.float32: 2
}


def gen_golden_data_simple():

    # dtype = bfloat16
    # dtype = np.float16
    dtype = np.float32

    # 核均匀分配dim，单核中仅单till:
    # input_shape = [8, 256] # 行测试
    # input_shape = [256, 8] # 列测试

    # 核均匀分配dim，单核中多till:
    # input_shape = [16, 256] # 行测试
    # input_shape = [256, 16] # 列测试

    # 核不均匀分配dim，单核中多till:
    # input_shape = [17, 256] # 行测试
    # input_shape = [256, 17] # 列测试

    # 核数多于dim:
    # input_shape = [3, 256] # 行测试
    # input_shape = [256, 3] # 列测试

    ## 最复杂情况：核不均匀分配dim，单核中多till，每个till不对齐32Bytes:
    # input_shape = [17, 255] # 行测试
    # input_shape = [255, 17] # 列测试
    # input_shape = [17, 15] # 行测试
    input_shape = [15, 17] # 列测试


    input_x = np.random.uniform(1, 2, input_shape).astype(dtype)
    # dim = 0 # 行向量测试
    dim = 1 # 列向量测试
    p = 3.0
    max_norm = 9.85

    # print(input_x)
    # Renorm
    input_x_torch = torch.from_numpy(input_x)
    golden = torch.renorm(input_x_torch, p=p, maxnorm=max_norm, dim=dim).numpy().astype(dtype)
    tiling = np.array([
        input_shape[0] * input_shape[1],
        input_shape[0],
        input_shape[1],
        dtype_emu[dtype]
    ], dtype=np.uint32)
    tiling.tofile("./input/input_tiling.bin")
    input_x.tofile("./input/input_x.bin")
    golden.tofile("./output/golden.bin")



if __name__ == "__main__":
    gen_golden_data_simple()

